package com.towexin.application.system.controller;

import com.towexin.common.ResultData;
import com.towexin.config.mylogging.LogType;
import com.towexin.config.mylogging.MyLog;
import com.towexin.application.system.domain.SystemSetting;
import com.towexin.application.system.service.SystemSettingService;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * TODO
 *
 * @author 唐伟鑫
 * @version 1.0
 * @date 2021/4/27 16:37
 */
@Api(tags = "系统信息设置接口")
@RestController
@RequestMapping("system")
public class SystemSettingController {
    @Autowired
    private SystemSettingService service;

    @PostMapping("setting")
    @MyLog(type = LogType.UPDATE, operation = "修改系统设置")
    @RequiresPermissions("system.setting.edit")
    public ResultData setting(SystemSetting systemSetting){
        return service.saveOrUpdate(systemSetting)?ResultData.OK():ResultData.NO();
    }

    //@MyLog(type = 1, operation = "进入系统设置")
    @GetMapping("get")
    @RequiresPermissions("system.setting.info")
    public ResultData getSetting(String id){
        return ResultData.OK(service.getById(id));
    }

    @GetMapping("config")
    public Map<String, Object> getConfig(){
        return service.getSystemConfig();
    }
}
